package com.banana.manager.forest.service.impl.handle;

import com.banana.manager.forest.dao.handle.IPhdDao;
import com.banana.manager.forest.entity.handle.PhdBean;
import com.banana.manager.forest.service.iihandle.IPhdService;
import com.banana.manager.forest.util.PageInfoSize;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class PhdServiceImpl implements IPhdService {

    @Resource
    private IPhdDao phdDao;

    @Override
    public PhdBean addPhd(PhdBean phdBean) {
        phdDao.insert(phdBean);
        return phdDao.selectById(phdBean.getPhdId());
    }

    @Override
    public PhdBean findById(Integer id) {

        return phdDao.selectById(id);
    }

    @Override
    public PhdBean modifyPhd(PhdBean phdBean) {
        phdDao.updateById(phdBean);
        return phdDao.selectById(phdBean.getPhdId());
    }

    @Override
    public void deletePhd(Integer id) {
        phdDao.deleteById(id);
    }

    @Override
    public List<PhdBean> getAllPhd() {
        return phdDao.selectList(null);
    }

    @Override
    public PageInfo<PhdBean> findBlurPage(Integer page, String phdName, String phdType, String phdDepartment) {
        QueryWrapper<PhdBean> queryWrapper = new QueryWrapper<>();
        String phdNameNew = "%"+phdName+"%";
        String phdTypeNew = "%"+phdType+"%";
        String phdDepartmentNew = "%"+phdDepartment+"%";
        queryWrapper.like("phd_name",phdNameNew);
        queryWrapper.like("phd_type",phdTypeNew);
        queryWrapper.like("phd_department",phdDepartmentNew);
        PageHelper.startPage(page, PageInfoSize.pageSize);
        return PageInfo.of(phdDao.selectList(queryWrapper));
    }
}
